<link href="../Vista/bootstrap/css/estilos_tabla.css" rel="stylesheet" type="text/css" />
<?php
	require ("/../conexion/conexion.php");
	class Formulario{
		var $conn;
		var $conexion;
		var $mensajeExito;
		var $mensajeError;
		
		function Formulario(){
			$this->conexion= new  Conexion();				
			$this->conn=$this->conexion->conectarse();
			$this->mensajeExito="Registro Exitoso";
			$this->mensajeError="Error al Registrar";
		}
		//---------------------------------------------------------------------------------------------------------------------------		
		function registrar($LS00IDUS, $LS03NB, $LS04AP1, $LS05AP2, $LS07NV, $LS08SC){
			
			$queryRegistrar = "insert into ls_02_usuarios (LS00IDUS, LS03NB, LS04AP1, LS05AP2, LS07NV, LS08SC) 
			values ('".$LS00IDUS."', '".$LS03NB."', '".$LS04AP1."', '".$LS05AP2."', '".$LS07NV."', '".$LS08SC."')";
			$registrar = mysqli_query($this->conn, $queryRegistrar) or die(mysqli_error());			
			
			if($registrar){
				echo "<script>location.href='../Vista/Usuarios/index.php?mensaje=". $this->mensajeExito."';</script>";				
			}else{
				echo "<script>location.href='../Vista/Usuarios/index.php?mensaje=".$this->mensajeError."';</script>";
			}
		}		
		//---------------------------------------------------------------------------------------------------------------------------
		function listar(){
			$sql="select * from ls_02_usuarios";
			$rs=mysqli_query($this->conn, $sql);
			$i=0;
			if(mysqli_num_rows($rs)<1){
				echo "No hay estudiantes registrados";	
			}else{
			 echo "<table border='0' align='center' class='table_' >";
			 echo "<thead>
					<th>Id</th>
					<th>Nombre</th>
					<th>Apellido1</th>
					<th>Apellido2</th>
					<th>Grado</th>
					<th>Seccion</th>
					<th>Modificar</th>
					<th>Eliminar</th>
				</thead>";
			 while ($row = mysqli_fetch_array($rs)){	 								
			echo "<td align='center'>".$row["LS00IDUS"]."</td>";
			echo "<td align='center'>".$row["LS03NB"]."</td>";	
			echo "<td align='center'>".$row["LS04AP1"]."</td>";
			echo "<td align='center'>".$row["LS05AP2"]."</td>";			
			echo "<td align='center'>".$row["LS07NV"]."</td>";			
			echo "<td align='center'>".$row["LS08SC"]."</td>";
						
			echo '<td align="center">
			<a class="fancybox fancybox.iframe" href="../../Vista/Usuarios/fancyBoxModificar.php?id='.'&Id='.$row["LS00IDUS"].'&Nombre='.$row["LS03NB"].'&Apellido1='.$row["LS04AP1"].'&Apellido2='.$row["LS05AP2"].'&Grado='.$row["LS07NV"].'&Seccion='.$row["LS08SC"].'" >Editar</a></td>';
			echo "<td><a href='../Controlador/controlador.php?eliminar=si&codigo=".$row["LS00IDUS"]."'>Eliminar</a></td></tr>";;
			$i++; 
			}			
			}
			echo "</table>";
		}
		//---------------------------------------------------------------------------------------------------------------------------
		function modificarUsuario($LS00IDUS, $LS03NB, $LS04AP1, $LS05AP2, $LS07NV, $LS08SC, $LS00IDUS){
			$queryUpdate = "update ls_02_usuarios set LS00IDUS = '$LS00IDUS', LS03NB = '$LS03NB', LS04AP1 = '$LS04AP1', LS05AP2 = '$LS05AP2', LS07NV = '$LS07NV', LS08SC = '$LS08SC' where LS00IDUS = '$LS00IDUS'";
			$update =mysqli_query($this->conn, $queryUpdate);	
			if($update){
				echo "Actualizacion Exitosa";
			}else{
				echo "Error Al Actualizar";
				}
		}
		//---------------------------------------------------------------------------------------------------------------------------
		function eliminar($pk){
			$queryDelete = "delete from ls_02_usuarios where LS00IDUS = ".$pk;
			$delete =mysqli_query($this->conn, $queryDelete);
			if($delete){						
				echo "<script>
						alert('Eliminacion exitosa');
						location.href='../Vista/Usuarios/modificarInformacion.php';
				</script>";				
			}else{
				echo "<script>
						alert('Error Al Eliminar');
						location.href='../Vista/Usuarios/modificarInformacion.php';
				</script>";	
				}
		}
		//--------------------------------------------------------------------------------------------------------------
		function buscar($dato){
			$sql="select * 
			from ls_02_usuarios
			where LS00IDUS like '%".$dato."%' OR LS03NB like '%".$dato."%' OR LS04AP1 like '%".$dato."%' OR LS05AP2 like '%".$dato."%' OR LS07NV like '%".$dato."%' OR LS08SC like '%".$dato."%'";
			$rs=mysqli_query($this->conn, $sql);
			$i=0;
			if(mysqli_num_rows($rs)<1){
				echo "La busqueda no obtuvo resultados.";	
			}else{
			echo "<table border='0' align='center' class='table_' ><thead>
					<th>Id</th>
					<th>Nombre</th>
					<th>Apellido1</th>
					<th>Apellido2</th>
					<th>Grado</th>
					<th>Seccion</th>
					<th>Modificar</th>
					<th>Eliminar</th>
				</thead><tbody>";
			 while ($row = mysqli_fetch_array($rs)){	 								
			echo "<tr><td align='center'>".$row["LS00IDUS"]."</td>";
			echo "<td align='center'>".$row["LS03NB"]."</td>";
			echo "<td align='center'>".$row["LS04AP1"]."</td>";
			echo "<td align='center'>".$row["LS05AP2"]."</td>";
			echo "<td align='center'>".$row["LS07NV"]."</td>";
			echo "<td align='center'>".$row["LS08SC"]."</td>";
			echo '<td align="center">
			<a class="fancybox fancybox.iframe" href="../Vista/Usuarios/fancyBoxModificar.php?id='.$row["LS00IDUS"].'&LS00IDUS='.$row["LS00IDUS"].'&LS03NB='.$row["LS03NB"].'&LS04AP1='.$row["LS04AP1"].'&LS05AP2='.$row["LS05AP2"].'&LS07NV='.$row["LS07NV"].'&LS08SC='.$row["LS08SC"].'" >Editar</a></td>';
			echo "<td><a href='../Controlador/controlador.php?eliminar=si&codigo=".$row["LS00IDUS"]."'>Eliminar</a></td></tr>";
			$i++; 
			}			
			}
			echo "</tbody></table>";
		}
	}
?>